home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 356 / defs / files.def < prev    next >
Text File  |  1992-03-11  |  7KB  |  191 lines

  1. DEFINITION MODULE Files;
  2.  
  3. (*
  4. *    Copyright (c) 1985, 1986 by
  5. *    Djavaheri Bros., Foster City, California.
  6. *    All Rights Reserved.
  7. *
  8. *    This software is furnished under a license and may be used and copied
  9. *    only  in accordance with  the  terms  of  such  license and  with the
  10. *    inclusion of the above copyright notice.  This software or  any other
  11. *    copies thereof may not be provided or otherwise made available to any
  12. *    other  person.   No title to and ownership of the  software is  herby
  13. *    transferred.
  14. *
  15. *    The information in this software is  subject to change without notice
  16. *    and  should  not be construed as a commitment by Djavaheri Bros.   No
  17. *    warranty is implied or expressed.
  18. *
  19. *   SCCID  = "1.2    9/19/86"; 
  20. *)
  21.  
  22.  
  23. (*                                      
  24. *    History of Modifcation                           
  25. *    Date        Who    Reasone             
  26. *       01/09/86        K.Y.    Add IsAtty : BOOLEAN to the file descriptor
  27.  
  28. *)
  29. FROM SYSTEM IMPORT ADDRESS;
  30. FROM SYSTEMX IMPORT MERROR;
  31.  
  32. EXPORT QUALIFIED
  33.     File,         FileDescriptor, FileState,    FilePosition,
  34.     BinTextMode,  ReadWriteMode,  ReplaceMode,
  35.     Open,         Create,         Close,        Remove,
  36.     Reset,        Rewrite,        Truncate,     Flush,
  37.     EOF,          State,          ResetState,   CloseAll,
  38.     GetFileName,  StateSet,BuffSize,SetFileError, Lookup;
  39.  
  40. TYPE
  41.     BinTextMode   = (binMode, textMode);
  42.     ReadWriteMode = (readOnly, readWrite, appendOnly);
  43.     ReplaceMode   = (noReplace, replace);
  44.  
  45.     FileState = (ok,
  46.         atEol,            (* just read an EOL *)
  47.         atEof,            (* just positioned at EOF *)
  48.                           (* errors opening files *)
  49.         nameError,        (* illegal syntax in file name as passed   *)
  50.         noFile,           (* file with specified name not found      *)
  51.         existingFile,     (* file already exists                     *)
  52.                           (* errors opening or operating *)
  53.         deviceError,      (* some hardware error during I/O          *)
  54.         noMoreRoom,       (* no room on volume/medium/directory      *)
  55.         accessError,      (* protect, read/write, binary/text error  *)
  56.                           (* errors operating upon a file *)
  57.         notOpen,          (* operation on unopened file              *)
  58.         endError,         (* read attempted after EOL or EOF         *)
  59.         outsideFile,      (* position before BOF or after EOF        *)
  60.                           (* and *)
  61.         otherError);      (* error unanticipated by this definition  *)
  62.  
  63.     StateSet = SET OF FileState;
  64.  
  65.     FilePosition = INTEGER;
  66.     (*     WARNING!   THIS IS NOT OPAQUE, BUT SHOULD BE TREATED AS SUCH.
  67.        Its contents are implementation-dependent, and should not be
  68.        manipulated directly.  It is implemented as a RECORD, not a POINTER,
  69.        so its contents may be written to/from other modules. It SHOULD be an 
  70.        opaque type, but this compromise was made so that its contents could be
  71.        recorded in files.
  72.        *)
  73.  
  74.     File = POINTER TO FileDescriptor;
  75.  
  76.     FileDescriptor = RECORD
  77.     (*     WARNING!   THIS IS NOT OPAQUE, BUT SHOULD BE TREATED AS SUCH. *)
  78.             link       : File;    (* Files are kept in a list *)
  79.             lun, rlun  : CARDINAL;    (* unit number for I/O *)
  80.             BufferSize : CARDINAL;
  81.             FileBuffer : ADDRESS;
  82.                 ReadCount  : INTEGER;     (* Buffer is read in *)
  83.                         HighMark   : CARDINAL;
  84.             position   : FilePosition;
  85.             namelen    : CARDINAL;
  86.             Name       : ARRAY [0..80] OF CHAR;
  87.             State      : FileState;
  88.             BinText    : BinTextMode;
  89.             ReadWrite  : ReadWriteMode;
  90.                 BufferEof  : BOOLEAN;     (* Buffer is at eof *)
  91.             Dirty      : BOOLEAN;     (* Buffer is marked *)
  92.                         IsAtty     : BOOLEAN;
  93.               END;
  94.  
  95.  VAR BuffSize:CARDINAL;
  96.  
  97.     
  98. (* Lookup for a file. The user has 2 ways to use this routine :
  99.    1. pass in signal = TRUE which means :
  100.        If the file the user looks for is not found, then create a file with 
  101.        the file name given.
  102.    2. pass in signal = FALSE which means
  103.        If the file the user looks for is not found , then do nothing - don't
  104.        created a new file.
  105.    The signal returns what this routine did :
  106.        if the returned signal = TRUE,  it means a file is created or opened.
  107.        if the returned signal = FALSE, it means a file is NOT created or opened.
  108.   *)
  109.  
  110. PROCEDURE Lookup( VAR f : File;
  111.                   VAR fileName : ARRAY OF CHAR;
  112.                   VAR signal   : BOOLEAN);
  113.  
  114. PROCEDURE Open  (* Open an existing external file; error if not present *)
  115.  
  116.   ( VAR file      : File;
  117.     VAR name      : ARRAY OF CHAR;
  118.         binText   : BinTextMode;
  119.         readWritemode : ReadWriteMode;
  120.     VAR state     : FileState);
  121.  
  122. PROCEDURE Create (* Create a new external file. If named file already exists,
  123.                     then overwrite only if overwriteMode = overwriteEnable,
  124.                     otherwise, error *)
  125.  
  126.   ( VAR file      : File;
  127.     VAR name      : ARRAY OF CHAR;
  128.         binText   : BinTextMode;
  129.         replace   : ReplaceMode;
  130.     VAR state     : FileState);
  131.  
  132. PROCEDURE Close (* Close the file, saving the external file *)
  133.  
  134.   ( VAR file     : File;
  135.     VAR state    : FileState);
  136.  
  137. PROCEDURE CloseAll(* Close all the open files, including SimpleIO *)
  138.     (VAR state    : FileState);
  139.  
  140.  
  141. PROCEDURE Remove (* Close the file, removing the external file *)
  142.  
  143.   ( VAR file     : File;
  144.     VAR state    : FileState);
  145.  
  146. PROCEDURE Reset (* Reposition to the start of the file *)
  147.  
  148.   (     file      : File;
  149.     VAR state     : FileState);
  150.  
  151. PROCEDURE Rewrite (* Reposition to start of file and then truncate file *)
  152.  
  153.   (     file      : File;
  154.     VAR state     : FileState);
  155.  
  156. PROCEDURE Truncate (* Set the end of the file to the current position *)
  157.  
  158.   (     file      : File;
  159.     VAR state     : FileState);
  160.  
  161. PROCEDURE Flush (* Writes any modified buffers to the storage medium *)
  162.  
  163.   (     file      : File;
  164.     VAR state     : FileState);
  165.  
  166. PROCEDURE EOF (* Returns true if last operation was not performed.
  167.                  (Value of true is caused by end of file or error    *)
  168.  
  169.   (     file      : File) : BOOLEAN;
  170.  
  171. PROCEDURE State (* Returns the current state of the file *)
  172.  
  173.   (    file      : File) : FileState;
  174.  
  175. PROCEDURE ResetState (* Allows continued operation in presence of error 
  176.                         conditions; reevaluates EOF/EOL so that they 
  177.                         really indicate file position.                   *)
  178.  
  179.   (     file      : File;
  180.     VAR state     : FileState);
  181.  
  182. PROCEDURE GetFileName (* Return complete and unambiguous file name *)
  183.  
  184.   (     file     : File;
  185.     VAR name     : ARRAY OF CHAR;
  186.     VAR state    : FileState);
  187.  
  188. PROCEDURE SetFileError(VAR state: FileState; ErrorNumber:MERROR);
  189.  
  190. END Files.
  191.